# -*- coding: utf-8 -*-
# TBIR服务
# @Time    : 2024/12/9 上午12:49
# @Author  : 赵鑫源
# @FileName: tbir_server.py
# @Software: PyCharm

from flask import Flask, request
from flask_cors import CORS
import generate_vectors
import search_image_vectors
import my_logging
from init_load_vectors import LoadImageVectors
import os

os.environ['KMP_DUPLICATE_LIB_OK'] = 'TRUE'  # 添加到Python脚本开头
logging = my_logging.LogUtils().get_log()
load_image_vectors = LoadImageVectors()
app = Flask(__name__)
CORS(app)


@app.route('/generate_image_vectors', methods=['POST'])
def generate():
    """
        生成图片向量
    """
    # 接收图片数据库信息对象
    img_object = request.get_json()
    return generate_vectors.build_vectors(img_object)


@app.route('/find_image_vectors', methods=['POST'])
def find_image_vectors():
    """
        查找图片
    """
    # 获取文件
    file = request.files['file']
    return search_image_vectors.find_image_vectors(file, 100)


if __name__ == '__main__':
    logging.info('~~~TBIR启动成功~~~')
    app.run(host='0.0.0.0', port=8998)
